﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KATS_Client
{
    /// <summary>
    /// Handles the output of progress reports
    /// </summary>
    public static class ProgressReporting
    {
        /// <summary>A collection of starting times</summary>
        static List<DateTime> StartTimes = new List<DateTime>(20);
        
        /// <summary>Start a new progress object</summary>
        /// <param name="message">The message for this object</param>
        /// <returns>The value of this start time</returns>
        public static int Start(string message)
        {
            message = message.Trim();
            Console.WriteLine("-> " + message);
            level++;

            StartTimes.Add(DateTime.Now);
            return StartTimes.Count - 1;
        }

        /// <summary>End the most recent progress object</summary>
        public static void End(int pos, string message)
        {
            level--;
            int time = (int)((DateTime.Now - StartTimes[pos]).TotalMilliseconds);

            Console.WriteLine("FINISHED: {0} [{1}ms]", message, time);
        }


        /// <summary>The current action failed</summary>
        public static void Failed(string message)
        {
            level--;
            Console.WriteLine("FAILED: " + message);
        }

        /// <summary>How deep is the current message</summary>
        static int level = 0;
    }
}
